package com.yuyou.train.user.controller;

import com.yuyou.train.service.api.user.entity.User;
import com.yuyou.train.user.service.IUserService;
import com.yuyou.train.user.vo.resp.RespUserLookTop;
import com.yuyou.train.user.vo.resp.RespUserRaiseTop;
import com.yuyou.train.util.bean.LoginRedisObj;
import com.yuyou.train.util.enums.CommEnums;
import com.yuyou.train.util.enums.user.UserLookEnums;
import com.yuyou.train.util.enums.user.UserPraiseEnums;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;  import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.user.service.IUserLookService;
import com.yuyou.train.util.bean.ReturnResult;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Validated
@RestController
@RequestMapping(value="/api/userLook")
public class UserLookController extends BaseController{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IUserLookService userLookService;

	@Autowired
	private IUserService userService;

	@ApiOperation(value = "添加浏览数")
	@RequestMapping(value="/addLook",method=RequestMethod.POST)
	public ReturnResult addLook(String foreignId,String type){		
		userLookService.addLook(foreignId, type);
		return ReturnResult.success();
	}

	@ApiOperation(value = "最多浏览推荐(前台)")
	@RequestMapping(value="/findUserLookTop", method = RequestMethod.POST)
	public ReturnResult<List<RespUserLookTop>> findUserLookTop(HttpServletRequest request){

		LoginRedisObj loginObj = this.getUserObj(request);
		User user = userService.selectByPrimaryKey(loginObj.getUserId());

		List<RespUserLookTop> userLookTopList = userLookService.findUserLookTop(user.getClassId(), CommEnums.resourceType.thought.getValue());
		return ReturnResult.success(userLookTopList);
	}
	
}
